﻿using System;
using System.Web;
using System.Web.Caching;
using WebAppMatrix.Extensions;

namespace WebAppMatrix.Caching
{
    public class HttpCacheProvider : CacheBase
    {
        static System.Web.Caching.Cache _cache = HttpRuntime.Cache;
        private System.Web.Caching.Cache cache
        {
            get
            {
                return _cache;
            }
        }

        #region CacheBase方法

        public override T Get<T>(string key, params object[] keyArgs)
        {
            return cache.Get<T>(key, keyArgs);
        }

        public override T Fetch<T>(string key, Func<T> callIfGetReturnsNull, params object[] keyArgs)
        {
            return cache.Fetch(key, callIfGetReturnsNull, keyArgs);
        }

        public override T Fetch<T>(string key, Func<T> callIfGetReturnsNull, DateTime absoluteExpiration, params object[] keyArgs)
        {
            return cache.Fetch(key, callIfGetReturnsNull, absoluteExpiration, keyArgs);
        }

        public override T Fetch<T>(string key, Func<T> callIfGetReturnsNull, TimeSpan slidingExpiration, params object[] keyArgs)
        {
            return cache.Fetch(key, callIfGetReturnsNull, slidingExpiration, keyArgs);
        }


        public override T Fetch<T>(string key, Action<T> callIfGetReturnsValue, Func<T> callIfGetReturnsNull, params object[] keyArgs)
        {
            return cache.Fetch(key, callIfGetReturnsValue, callIfGetReturnsNull, keyArgs);
        }

        public override T Fetch<T>(string key, Action<T> callIfGetReturnsValue, Func<T> callIfGetReturnsNull, DateTime absoluteExpiration, params object[] keyArgs)
        {
            return cache.Fetch(key, callIfGetReturnsValue, callIfGetReturnsNull, absoluteExpiration, keyArgs);
        }

        public override T Fetch<T>(string key, Action<T> callIfGetReturnsValue, Func<T> callIfGetReturnsNull, TimeSpan slidingExpiration, params object[] keyArgs)
        {
            return cache.Fetch(key, callIfGetReturnsValue, callIfGetReturnsNull, slidingExpiration, keyArgs);
        }

        public override void Insert(string key, object data, params object[] keyArgs)
        {
            cache.Insert(key, data, keyArgs);
        }

        public override void Insert(string key, object data, DateTime absoluteExpiration, params object[] keyArgs)
        {
            cache.Insert(key, data, absoluteExpiration, keyArgs);
        }

        public override void Insert(string key, object data, TimeSpan slidingExpiration, params object[] keyArgs)
        {
            cache.Insert(key, data, slidingExpiration, keyArgs);
        }

        public override void Remove(string key, params object[] keyArgs)
        {
            cache.Remove(key, keyArgs);
        }

        public override void RemoveAll()
        {
            cache.RemoveAll();
        }

        public override int Count()
        {
            return cache.Count;
        }

        #endregion
    }
}
